import request from 'umi-request';
import moment from 'moment';
import orderBy from 'lodash/orderBy';


export async function getEmployeeById(id) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getEmployeeById/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function queryScorePage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryScorePage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function queryContractMangerPage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryContractMangerPage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function queryProtocolPersonnelPage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryProtocolPersonnelPage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getContractSubjectList() {
  return request('/hr-ssc/api/api-admin/eSign/getCompanyList', {
    method: 'post',
  }).then((res) => {
    return res.data;
  });
}

export async function getContractModelList() {
  return request('/hr-ssc/api/api-admin/eSign/getContractModelList', {
    method: 'post',
    data:{
      type:6,
      kind:1
    },
    requestType: 'form'
  }).then((res) => {
    return res.data;
  });
}

export async function getAttendMonth(params,code) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getAttendMonth`, {
    method: 'post',
    data:{
      startDate: params.date ? params.date[0] : moment().date(1),
      endDate: params.date ? params.date[1] : moment().date(31),
      code:code
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getUserBankCardInfo(oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getUserBankCardInfo`, {
    method: 'get',
    params:{
      oid:oid
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: [data],
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getCredentialList(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getCredentialList`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid
    },
    requestType: 'form'
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function queryCertificatePage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryCertificatePage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getPersonSecurityList(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getPersonSecurityList`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
      dateStart:params.data && params.data[0],
      dateEnd:params.data && params.data[1],
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getPersonFundsList(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getPersonFundsList`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
      dateStart:params.data && params.data[0],
      dateEnd:params.data && params.data[1],
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getAwardInfoList(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getAwardInfoList`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
      dateStart:params.data && params.data[0],
      dateEnd:params.data && params.data[1],
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getReAndPu() {
  return request(`/hr-ssc/api/api-admin/job/findReAndPu`, {
    method: 'get',
  }).then((res) =>{
    return res.data;
  });
}

export async function getSalaryChangeList(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getSalaryChangeList`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
      dateStart:params.data && params.data[0],
      dateEnd:params.data && params.data[1],
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getRecruitment(oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/getRecruitment`, {
    method: 'get',
    params:{
      oid:oid
    }
  }).then((res) =>{
    return res.data;
  });
}

export async function getEmployeeChange(params,code) {
  return request(`/hr-ssc/api/api-admin/neusoft/getEmployeeChange`, {
    method: 'post',
    data:{
      pageNum: params.current,
      pageSize: params.pageSize,
      code:code
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getNodeList(code) {
  return request(`/hr-ssc/api/api-admin/neusoft/getNodeList`, {
    method: 'post',
    data:{
      code:code
    }
  }).then((res) =>{
    return res.data;
  });
}

export async function getEmployeeSalaryModule(code) {
  return request(`/hr-ssc/api/api-admin/neusoft/getEmployeeSalaryModule`, {
    method: 'get',
    params:{
      code:code
    }
  }).then((res) =>{
    return res.data;
  });
}

export async function getEmployeeSalary(params,code) {
  return request(`/hr-ssc/api/api-admin/neusoft/getEmployeeSalary`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      code:code,
      yymm:params.data && params.data[0],
      endyymm:params.data && params.data[1],
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      const newList = data.list.map((item)=>{
        let time = item.month.replace('年','-').replace('月','')
        return {...item, time:moment(time).format('YYYY-MM')}
      })
      return {
        current: data.currPage,
        data: orderBy(newList,['time'], ['desc']),
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getPerformanceList(params,code) {
  return request(`/hr-ssc/api/api-admin/neusoft/getPerformanceList`, {
    method: 'get',
    params:{
      code:code,
      assessMonthStart:params.date ? params.date[0] : moment().month(0),
      assessMonthEnd:params.date ? params.date[1] : moment()
    }
  }).then((res) =>{
    return {data : res.data};
  });
}

export async function queryEmployeeEducationPage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryEmployeeEducationPage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function queryEmployeeSocietyexperiencePage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryEmployeeSocietyexperiencePage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function queryEmployeeInorgnamePage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryEmployeeInorgnamePage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function queryFamilyMemberPage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryFamilyMemberPage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function queryRelativeRecordsPage(params,oid) {
  return request(`/hr-ssc/api/api-admin/employeeBasis/queryRelativeRecordsPage`, {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      oid:oid,
    }
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}
